// SPDX-License-Identifier: GPL-2.0
/*
 * SCHEDULE: HARD-LOCKUP
 *
 *  - KERNEL: ENABLE CONFIG_HARDLOCKUP_DETECTOR
 *
 * (C) 2024.05.19 BiscuitOS <buddy.zhang@aliyun.com>
 */
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/sched/signal.h>

static struct task_struct *kthread;

static int hard_lockup_fn(void *data)
{
	/* DISABLE INTERRUPT */
	local_irq_disable();

	while (!kthread_should_stop()) {
		/* EMULATE OCCUPY CPU */
		;
	}

	/* ENABLE INTERRUPT */
	local_irq_enable();
	printk("HARD LOCKUP KTHREAD STOPPING\n");

	return 0;
}

static int __init BiscuitOS_init(void)
{
	kthread = kthread_run(hard_lockup_fn, NULL, "BiscuitOS-HARD-LOCKUP");
	if (!kthread)
		return -EINVAL;

	return 0;
}

static void __exit BiscuitOS_exit(void) { }

module_init(BiscuitOS_init);
module_exit(BiscuitOS_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("BiscuitOS <buddy.zhang@aliyun.com>");
MODULE_DESCRIPTION("BiscuitOS OOPS");
